<?php

class Help extends Controller {
	
	function Help() {
		parent::Controller();
	}
	
	var $str = '';
	
	function imprimeMenu( $atual, array $menuTotal , $idPai = null, $nivel = 0 )
	{
		$this->str .=  str_repeat( "" , $nivel ).'<ul>'.PHP_EOL;
		
		foreach( $menuTotal[$idPai] as $idMenu => $menuItem)
		{
			if( ! $idPai)
				$li = '<li class="pai">';
			else
				$li = '<li class="filho">';
			
			$a = '<a %s href="'.base_url().'help/indice/%d-%s.html">%s</a>';
			
			if($atual == $idMenu)
				$class = ' class="itemAtual"';
			else
				$class = '';			
			
			$this->str .=  str_repeat( "" , $nivel + 1 ).$li.sprintf($a, $class, $idMenu, url_title($menuItem['titulo']), $menuItem['titulo']).PHP_EOL;
			
			if( isset( $menuTotal[$idMenu] ) ) $this->imprimeMenu($atual, $menuTotal , $idMenu , $nivel + 2);
			
			$this->str .=  str_repeat( "" , $nivel + 1 ).'</li>'.PHP_EOL;
		}
		
		$this->str .=  str_repeat( "" , $nivel ).'</ul>'.PHP_EOL;
		
		return $this->str;
	}
	
	function indice($atual)
	{
		$indices = $this->help->getIndice();
		$this->str = '';
		$indice = $this->imprimeMenu((integer)$atual, $indices);
		
		//$data = array('string'=>$indice);
		
		return $indice;
	}
	
	function conteudo($atual)
	{		
		if($atual === 0)
			return 'Bem vindo!';
		$conteudo = array();

		$conteudo = $this->help->getConteudo($atual);
		
		return $conteudo->texto;
	}
	
	function showHelp($atual)
	{
		$this->load->helper('url');
		$this->load->model('helpmodel', 'help');

		$data = array('indice'=>$this->indice((integer)$atual), 'texto'=>$this->conteudo((integer)$atual));
		
		$this->load->view('helpview',$data);
	}
	
	function index()
	{
		$atual = 0;
		
		$this->load->helper('url');
		$this->load->model('helpmodel', 'help');
		
		$data = array('indice'=>$this->indice($atual), 'texto'=>$this->conteudo($atual));
		
		$this->load->view('helpview',$data);
		
	}
}
?>